package mumu.android;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mumu.android.crypt.json;
import mumu.android.crypt.shared;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class CryptActivity extends FragmentActivity {
	List<Map> myData = new ArrayList<Map>();;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ListView lv = new ListView(this);
		lv.setAdapter(new SimpleAdapter(this, getData(), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 }));
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Map map = (Map) myData.get(position);
				DialogFragment dialogFragment = (DialogFragment) map.get("intent");
				dialogFragment.show(getSupportFragmentManager(), "dialog");
			}
		});

		setContentView(lv);
	}

	protected List getData() {
		addItem(myData, "SharedPreferences", new shared());
		addItem(myData, "json", new json());
		return myData;
	}

	protected void addItem(List<Map> data, String name, DialogFragment dialogFragment) {
		Map<String, Object> temp = new HashMap<String, Object>();
		temp.put("title", name);
		temp.put("intent", dialogFragment);
		data.add(temp);
	}
}
